package me.zhengjie.sqlservilce.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import me.zhengjie.mapper.IwsSOutsideMapper;
import me.zhengjie.pojo.entity.IwsStoreOutside;
import me.zhengjie.sqlservilce.IwsStoreOutsideService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
@RequiredArgsConstructor
public class IwsSOutsideServiceImpl extends ServiceImpl<IwsSOutsideMapper, IwsStoreOutside> implements IwsStoreOutsideService {
    private final IwsSOutsideMapper iwsSOutsideMapper;

    @Override
    public List<IwsStoreOutside> selectStoreTypeStatus(String storeType, Integer status) {
        LambdaQueryWrapper<IwsStoreOutside> iwsSLocalLambdaQueryWrapper = new LambdaQueryWrapper<>();
        iwsSLocalLambdaQueryWrapper.eq(IwsStoreOutside::getStoreType,storeType)
                .eq(IwsStoreOutside::getStatus,status)
//                .eq(IwsSOutside::getFloor,1)
                .eq(IwsStoreOutside::getIsLock,0);
//                .isNull(IwsSOutside::getContainerCode);
        return iwsSOutsideMapper.selectList(iwsSLocalLambdaQueryWrapper);
    }

    @Override
    public boolean updateStatus(String sId,String container, int status) {
        LambdaUpdateWrapper<IwsStoreOutside> iwsSLocalLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        iwsSLocalLambdaUpdateWrapper.set(IwsStoreOutside::getStatus,status)
                .set(IwsStoreOutside::getUpdateDate, LocalDateTime.now())
                .set(IwsStoreOutside::getContainerCode, container)
                .eq(IwsStoreOutside::getId,sId);
        return iwsSOutsideMapper.update(null,iwsSLocalLambdaUpdateWrapper) >0;
    }

    @Override
    public boolean updateStatus(String sId, int status) {
        LambdaUpdateWrapper<IwsStoreOutside> iwsSLocalLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        iwsSLocalLambdaUpdateWrapper.set(IwsStoreOutside::getStatus,status)
                .set(IwsStoreOutside::getUpdateDate, LocalDateTime.now())
                .eq(IwsStoreOutside::getId,sId);
        return iwsSOutsideMapper.update(null,iwsSLocalLambdaUpdateWrapper) >0;
    }

    @Override
    public IwsStoreOutside selectStorageCode(String storageCode) {
        LambdaQueryWrapper<IwsStoreOutside> iwsSOutsideLambdaQueryWrapper = new LambdaQueryWrapper<>();
        iwsSOutsideLambdaQueryWrapper.eq(IwsStoreOutside::getId,storageCode);
        return iwsSOutsideMapper.selectOne(iwsSOutsideLambdaQueryWrapper);
    }

    @Override
    public IwsStoreOutside selectCircleLibrary(String storeType, int status) {
        LambdaQueryWrapper<IwsStoreOutside> iwsSLocalLambdaQueryWrapper = new LambdaQueryWrapper<>();
        iwsSLocalLambdaQueryWrapper.eq(IwsStoreOutside::getStoreType,storeType)
                .eq(IwsStoreOutside::getStatus,status)
                .eq(IwsStoreOutside::getFloor,1)
                .isNotNull(IwsStoreOutside::getContainerCode);
        return iwsSOutsideMapper.selectOne(iwsSLocalLambdaQueryWrapper);
    }

    @Override
    public List<IwsStoreOutside> selectStoreName(String storeName) {
        LambdaQueryWrapper<IwsStoreOutside> iwsSOutsideLambdaQueryWrapper = new LambdaQueryWrapper<>();
        iwsSOutsideLambdaQueryWrapper.eq(IwsStoreOutside::getStoreName,storeName)
                .eq(IwsStoreOutside::getStatus,3)
                .isNotNull(IwsStoreOutside::getContainerCode);
        return iwsSOutsideMapper.selectList(iwsSOutsideLambdaQueryWrapper);
    }

    @Override
    public IwsStoreOutside selectId(String id) {
        LambdaQueryWrapper<IwsStoreOutside> iwsStoreOutsideLambdaQueryWrapper = new LambdaQueryWrapper<>();
        iwsStoreOutsideLambdaQueryWrapper.eq(IwsStoreOutside::getId,id);
        return iwsSOutsideMapper.selectOne(iwsStoreOutsideLambdaQueryWrapper);
    }
}
